/**
 * Created by yangxianming on 2020/12/30.
 */

//
//接口定义 都是以api开头 所需参数都通过方法传入
//function apiGetCorpList(dofun, envText){}
//
//获取项目列表数据
function apiShowList(dofun, id){
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("get", "/progress/showProgress?action=forMobile&id="+id, true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    dofun(r["result"]);
                }
                if(r["apiStatus"] == "2"){
                    //项目归档后页面则么显示
                    var tr = document.getElementById("th");
                    tr.innerText = "";
                    var th = document.createElement("th");
                    th.innerText = r["result"];
                    tr.appendChild(th);
                }
                if (r["apiStatus"] == "0"){
                    alert(r["errorMsg"]);
                }
            }
        }
    };
    xmlHttp.send();
}

//
//页面渲染 都是以draw开头
//function drawGetCorpList(data){}
//
function drawShowList(data){
    var tbody = document.getElementById("tbody");
    var th = document.getElementById("th");
    tbody.innerText = "";
    tbody.appendChild(th);
    document.getElementById("progressname").innerText = data["progressname"] + "总体测试进度";
    document.getElementById("totalProportion").innerText = data["totalProportion"] + "%";

    var detail = JSON.parse(data["detail"]);

    for(var one in detail){
        var tr = document.createElement("tr");

        var td1 = document.createElement("td");
        td1.innerText = detail[one][0];
        tr.appendChild(td1);

        var td2 = document.createElement("td");
        td2.innerText = detail[one][1];
        tr.appendChild(td2);

        var td3 = document.createElement("td");
        var v3 = detail[one][2];
        td3.innerText = "是";
        if(v3 == "n"){
            td3.innerText = "否";
            tr.style.backgroundColor = "rgba(212, 98, 116, 0.28)";
        }
        tr.appendChild(td3);

        var td4 = document.createElement("td");
        td4.innerText = detail[one][3];
        tr.appendChild(td4);

        var td5 = document.createElement("td");
        td5.innerText = detail[one][4];
        tr.appendChild(td5);

        tbody.appendChild(tr);
    }

}

//
//页面调用 数据获取，接口层与渲染层的连接
//
function initializeData(){
    apiShowList(drawShowList, getQueryVariable("id"));

}